﻿
/**
 * Proyecto: Cognitum
 * Global IT Services 2008
 * @author 
 */

Cognitum.Cartera.Direccion.Entity = function (){
	if (LOG.isDebugEnabled()) {
		LOG.debug('[Cognitum.Cartera.Direccion.Entity.ctor] <-');
	}
	Cognitum.Cartera.Direccion.Entity.superclass.constructor.call(this, 
        false,
		true
	);
	if (LOG.isDebugEnabled()) {
		LOG.debug('[Cognitum.Cartera.Direccion.Entity.ctor] <-');
	}
}

Ext.extend(Cognitum.Cartera.Direccion.Entity, Karma.Core.Entity, {
	id: 'Direccion.Entity',
	name: 'Direcciones',
	editorXType: 'dir.editor',
	editorW: 600,
	editorH: 450,
	columns: [
		{ Name: 'Id', Property: 'Id', Mostrar: false },
		{ Name: 'Nombre', Property: 'Nombre' },
		{ Name: 'Tipo', Property: 'Tipo', Tipo: 'enum', 
			TipoEnum: 'Cognitum.Dominio.Cartera.TipoDireccionEnum' },
		{ Name: 'Pais', Property: 'Pais.Nombre', Mostrar: false },
		{ Name: 'Estado', Property: 'Estado.Nombre', Mostrar: false},
		{ Name: 'Calle', Property: 'Calle' },
		{ Name: 'N&uacute;mero (int)', Property: 'NumInterior' },
		{ Name: 'N&uacute;mero (ext)', Property: 'NumExterior' },
		{ Name: 'Colonia', Property: 'Colonia', Mostrar: false },
		{ Name: 'Cp', Property: 'Cp', Mostrar: false },
		{ Name: 'Delegaci&oacute;n', Property: 'Delegacion', Mostrar: false }
	],
	searchlist: {
		sortings: [ 'Nombre'],
		views: [
			{ Id: 0, Nombre: 'Normal', Template: null },
			{ Id: 1, Nombre: 'Expandida', Template: null }
		],
		previewTemplate: null		
	},
	aggregatelist: {
		getCustomActions: function(selModel) {
			return [{
		        text:'Mostrar Mapa...',
		        iconCls:'map-icon',
		        scope: this,
		        handler:function(){
					Ext.ComponentMgr.create({ 
						 	direccion: selModel.getSelected()
						}, 
						'dir.map'
					);
		        }
		    }];
		},
		mostrarMapa: function(direccion) {
			if (LOG.isDebugEnabled()) {
				LOG.debug('[Direccion.AggregateList.mostrarMapa] <-');
			}
			if(!Ext.ux.JSLoader.isLoaded(this.gmapsapi)) {
				if (LOG.isDebugEnabled()) {
					LOG.debug('[Direccion.AggregateList.mostrarMapa] loading google maps library');
				}
				new Ext.ux.JSLoader({
					url: this.gmapsapi,
					onLoad: this.gMapsLoaded.createDelegate(this),
					async: false,
					direccion: direccion
				});
			} else {
				if (LOG.isDebugEnabled()) {
					LOG.debug('[Direccion.AggregateList.mostrarMapa] google maps library loaded.');
				}
				this.gMapsLoaded({ direccion: direccion });
			}
			if (LOG.isDebugEnabled()) {
				LOG.debug('[Direccion.AggregateList.mostrarMapa] ->');
			}
		},
		gMapsLoaded: function(args) {
			Ext.ComponentMgr.create({ 
				 	direccion: args.direccion
				}, 
				'dir.map'
			);
		}
	},
	link: {
		displayProperty: 'Nombre'
	}
});

Cognitum.Direccion = Cognitum.Cartera.Direccion.Entity;